package net.xinqushi.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.orm.hibernate4.HibernateTemplate;
import org.springframework.stereotype.Component;

import net.xinqushi.dao.UserDAO;
import net.xinqushi.model.User;
@Component(value="sqlDAO")
@Scope(value="singleton")
//初始一个been
public class UserDAOMySqlImpl implements UserDAO {
	HibernateTemplate hibernateTemplate;
	@Resource
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}
	@Override
	public void save(User user) {
		// TODO Auto-generated method stub
		hibernateTemplate.merge(user);
	}
	@Override
	public boolean isExists(User user) { //用户名 密码
		// TODO Auto-generated method stub
		return hibernateTemplate.findByExample(user).size()>0;  //大于0存在
	}
	public User get(User user)
	{
		List<User>list=hibernateTemplate.findByExample(user);
		if(list.size()>0)
		{
			return list.get(0);
		}
		return null;
		
	}
}
